<?php
echo $javascript->link('http://maps.google.com/maps/api/js?sensor=false',false); 

$maps = '';
$points = '';
$markers = '';
$events = '';
$options = '';
$icons = '';
$adds = '';
foreach ($params as $m => $md) {

	foreach ($md['points'] as $p => $d) {
		if(isset($d['image'])){
			$icons .= "var selfIcon{$m}{$p} = new GIcon();\n";
			$icons .= "selfIcon{$m}{$p}.image = \"{$d['image']}\";\n";
			$icons .= "selfIcon{$m}{$p}.iconSize = new GSize({$d['iconSize1']}, {$d['iconSize2']});\n";
			$icons .= "selfIcon{$m}{$p}.iconAnchor = new GPoint(9, 34);\n";
			$icons .= "selfIcon{$m}{$p}.infoWindowAnchor = new GPoint(9, 2);\n";
	
			$points .= "var point{$m}{$p} = new GLatLng({$d['lat']},{$d['lng']});\n";
			$options .= "var options{$m}{$p} ={icon: selfIcon{$m}{$p} };";
			$markers .= "var marker{$m}{$p} = new GMarker(point{$m}{$p},options{$m}{$p});\n";
			$events .= "GEvent.addListener(marker{$m}{$p}, \"click\", function() {
			    marker{$m}{$p}.openInfoWindowHtml('{$d['content']}');
			 });\n";
	  
			$adds .= "{$m}.addOverlay(marker{$m}{$p});\n";
		}else{
			$center_lat = 0;
			$center_lng = 0;
		}
	}
	
	$maps .= "


		var {$m} = new GMap2(document.getElementById('{$m}'),{mapTypes:[G_SATELLITE_MAP,G_NORMAL_MAP,G_PHYSICAL_MAP]});
		{$m}.addControl(new GSmallMapControl());
		{$m}.addControl(new GMapTypeControl());
		{$m}.setCenter(new GLatLng({$md['center']['lat']}, {$md['center']['lng']}), {$md['zoom']});
		
		{$icons}
		{$points}
		{$options}
  		{$markers} 
	    {$events}
	    {$adds}
	    
	";
}
echo $javascript->codeBlock("

	// wyswietlanie mapy
	function initialize() {	    
	  {$maps}  		  		  
	}
	
	$(document).ready(function() {
		initialize();
	});
	",$options = array('allowCache'=>true,'safe'=>true,'inline'=>false));
?>
